import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_uikit/common/app_text_style.dart';
import 'package:flutter_uikit/widget/text/text_widget.dart';
import 'package:get/get.dart';
import 'list_view_logic.dart';

class ListViewPage extends StatefulWidget {
  const ListViewPage({Key? key}) : super(key: key);

  @override
  State<ListViewPage> createState() => ListViewPageState();
}

class ListViewPageState extends State<ListViewPage> {
  final logic = Get.put(ListViewLogic());
  final state = Get.find<ListViewLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(state.title ?? ""),
      ),
      body: ListView.builder(
          shrinkWrap: false,//列表的高度是否根据内容自动设定
          scrollDirection: Axis.vertical,//列表滑动方向
          itemCount:state.countryList.length,//item总个数
          itemBuilder: (BuildContext context, int index) {//每个item的布局
        String name = state.countryList[index]["name"];
        String desc = state.countryList[index]["desc"];
        return buildItemWidget(++index, name, desc);
      }),
    );
  }

  /// 构建item布局组件
  Widget buildItemWidget(int index, String name, String desc) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 16.w,vertical: 10.w),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            TextWidget(index.toString(), TS_FF1D2129_20_W5),
            SizedBox(width: 15.w),
            Expanded(child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                TextWidget(name, TS_FF1D2129_20_W5),
                TextWidget(desc, TS_FF1D2129_16_W5,maxLines: 3),
              ],
            ))
          ],
        ),
    );
  }
}
